<?php
ob_start();
?>
<?php
include ('encabezado.php');
//session_start();
$group = $_SESSION['group'];
if ($group != "Teacher")
{
	header('Location: viewmarks.php');
}

$markid = $_GET['edit'];
if(connectBD($ip, $userdb, $passworddb, $db))
{
	$query = "SELECT Mark, Type, Description, Date FROM Marks WHERE MarkID='$markid'";
	$result = mysql_query($query);
	while($row = mysql_fetch_assoc($result))
	{
		echo "<form action='' method='post'>";
		echo "<br><br><h2 align='center'>Edit Marks</h2><table border='2' align='center'>";
		echo "<tr><td align='center'>";
		echo "Mark:<br><input type='text' value='".$row['Mark']."' name='mark'><br>";
		echo "Type:<br><select name='type'><option value='exam'>Exam</option><option value='xp'>XP</option></select><br>";
		echo "Description:<br><input type='text' value='".$row['Description']."' name='description'><br>";
		echo "Date:<br><input type='text' id='campofecha' value='".$row['Date']."' readonly='readonly' name='date'><br><br>";
		echo "<input type='submit' name='button' value='Edit'>";
		echo "</td></tr>";
		echo "</table>";
		echo "</form>";
	}
	
	if($_SERVER['REQUEST_METHOD'] == 'POST')
	{
		$query = "UPDATE Marks SET Mark='".$_POST['mark']."', Type='".$_POST['type']."', Description='".$_POST['description']."', 
		Date='".$_POST['date']."' where MarkID='".$markid."'";
		$result = mysql_query($query);
		if (!mysql_query($result))
		{
			header('Location: viewmarks.php');
		}
		else
		{
			echo '<br> Not inserted.';
		}
	}
}
else
{
	echo "Error!"; //error con db
}
include ('pie.php');
?>
<?php
ob_end_flush();
?>